<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <meta charset="UTF-8">
    <title>座位订阅详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,room-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
    <style>
        .main{
            padding: 25px;
        }
        .seat-all{
            display: flex;
            flex-wrap: wrap;
        }
        .seat-item{
            width: 100px;
            height: 50px;
            display: inline-block;
            background: #cccccc;
            line-height: 25px;
            text-align: center;
            margin: 10px;
            box-sizing: border-box;
        }
        .seat-item:hover{
            cursor: pointer;
        }
        .seat-no-tip{
            color: white;
            font-size: 16px;
            font-weight: 700;
        }

        .bg-red{
            background-color: red;
        }
        .bg-green{
            background-color: green;
        }
        .all-tip{
            width: 400px;
            height: 200px;
            padding: 15px;
            font-size: 15px;
        }
        .item{
            height: 30px;
            line-height: 30px;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="main">
                    <div class="seat-all">
                        <span th:each="info,stat:${infoList}" th:class="${info.flag} ? 'seat-item bg-red' : 'seat-item bg-green'" th:title="'座位号' + ${info.timeRange}" th:onclick="confirmOrder([[${info}]], [[${dateinfo}]])">
                            <div class="seat-no-tip" th:text="${info.timeRange}"></div>
                            <div class="seat-no-tip" th:text="${info.flag} ? '已预订' : '可预订'"></div>
                        </span>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate', 'form', 'layer'],
        function () {
            var laydate = layui.laydate;

            //日期选择器
            laydate.render({
                elem: '#date'
            });
        });
</script>
<script>

    function confirmOrder(data, dateinfo) {
        const {id, flag, reservationMark,seatId,timeRange} = data
        if (flag) {
            $.ajax({
                url: "/seat/getSeatOrderInfo",
                type: "POST",
                data: {id},
                dataType: 'json',
                success: function (result) {
                    const {code, msg, data} = result
                    console.log(result)
                    const html = `
                           <div class="all-tip">
                                <div class="item">座位状态:<span style="color: red">已预订</span> <br/></div>
                                <div class="item">学院班级:${data.collageName} ${data.clazzName} <br/></div>
                                <div class="item">学生姓名:${data.name} <br/></div>
                                <div class="item">学生学号:${data.sno} <br/></div>
                                <div class="item">学生电话:${data.phone} <br/></div>
                                <div class="item">订座时间:${data.createTime} <br/></div>
                           </div>
                    `
                    if (code === 200) {
                        layer.open({
                            title:`预定信息`,
                            type: 1,
                            area: ['500px', '300px'],
                            content: html
                        });
                    } else {
                        layer.msg(msg);
                    }
                },
            });
        } else {
            layer.open({
                content: `预定座位,预约时间:${timeRange}`
                ,btn: ['预约']
                ,yes: function(index, layero){
                    const obj = {
                        date: dateinfo,
                        seatId: seatId,
                        mark: reservationMark
                    }
                    console.log(obj)
                    $.ajax({
                        url: "/seat/reservationSeat",
                        type: "POST",
                        data: JSON.stringify(obj),
                        contentType: 'application/json;charset=utf-8',
                        dataType: 'json',
                        success: function (result) {
                            const {code, msg} = result
                            if (code === 200) {
                                layer.msg("添加成功", function () {
                                    //关闭当前页面
                                    var index1 = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index1);
                                    //刷新父级页面
                                    window.parent.location.reload();
                                    return false;
                                });
                            } else {
                                layer.msg(msg);
                                layer.close(index);
                            }
                        },
                    });
                }
            });
        }
        console.log(data)
    }
</script>
</html>
